<!doctype html>
<!-- Copyright (c) 2015 Google Inc. All rights reserved. -->
<html>
<head>
  <meta charset="utf-8">
  <title>google-sheet tests</title>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">

  <script src="../../../platform/platform.js"></script>
  <link rel="import" href="../../../polymer-test-tools/tools.html">
  <script src="../../../polymer-test-tools/htmltest.js"></script>

  <link rel="import" href="../google-sheets.html">
</head>
<body>

<google-sheets id="sheet" key="0Anye-JMjUkZZdDBkMVluMEhZMmFGeHpYdDJJV1FBRWc"
               published></google-sheets>

<script>
document.addEventListener('polymer-ready', function() {

  var sheet = document.querySelector('#sheet');
  var root = sheet.shadowRoot;

  assert.isTrue(sheet.published);
  assert.isNull(root.querySelector('google-signin-aware'),
      'google-signin-aware should not be created for a published sheet');

  sheet.addEventListener('google-sheet-data', function(e) {

    if (e.detail.type === 'tab') {
      assert.equal(this.tab.title, 'Locations',
                   'Published spreadsheet title is not correct.');
      assert.isNotNull(this.tab.updated, '.tab.updated was not set');
      assert.isTrue(this.tab.authors.length > 0, '.tab.authors was 0');
    } else if (e.detail.type === 'rows') {
      assert.lengthOf(this.spreadsheets, 0,
        '.spreadsheets length should be 0 since spreadsheet key was given');
      assert.isTrue(this.rows.length > 0, '.rows was not populated');
    }

    assert.equal(this.$.cellrowsajax.url, '',
      '#cellrowsajax should not be invoked for a public spreadsheet');

    done();
  });
});
</script>
</body>
</html>
